package com.jintian.smart.platform.system.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.jintian.smart.kernel.common.controller.SupportBaseController;
import com.jintian.smart.kernel.core.constant.SwaggerTagConst;
import com.jintian.smart.kernel.core.domain.ResponseDTO;
import com.jintian.smart.base.api.system.form.ConfigAddForm;
import com.jintian.smart.base.api.system.form.ConfigQueryForm;
import com.jintian.smart.base.api.system.form.ConfigUpdateForm;
import com.jintian.smart.base.api.system.view.ConfigVO;
import com.jintian.smart.platform.system.service.ConfigService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.beetl.sql.core.page.PageResult;
import org.springframework.web.bind.annotation.*;

/**
 * 配置
 */
@RestController
@Tag(name = SwaggerTagConst.Support.CONFIG)
@RequestMapping("/sys/config")
public class ConfigController extends SupportBaseController {
    @Resource
    private ConfigService configService;

    @Operation(summary = "分页查询系统配置")
    @PostMapping("/query")
    @SaCheckPermission("support:config:query")
    public ResponseDTO<PageResult<ConfigVO>> queryConfigPage(@RequestBody @Valid ConfigQueryForm queryForm) {
        return configService.queryConfigPage(queryForm);
    }

    @Operation(summary = "添加配置参数")
    @PostMapping("/add")
    @SaCheckPermission("support:config:add")
    public ResponseDTO<String> addConfig(@RequestBody @Valid ConfigAddForm configAddForm) {
        return configService.add(configAddForm);
    }

    @Operation(summary = "修改配置参数")
    @PostMapping("/update")
    @SaCheckPermission("support:config:update")
    public ResponseDTO<String> updateConfig(@RequestBody @Valid ConfigUpdateForm updateForm) {
        return configService.updateConfig(updateForm);
    }

    @Operation(summary = "查询配置详情")
    @GetMapping("/queryByKey")
    public ResponseDTO<ConfigVO> queryByKey(@RequestParam String configKey) {
        return ResponseDTO.ok(configService.getConfig(configKey));
    }
}
